home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11757 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Pointers to structures question.
  5. Date: Mon, 25 Mar 96 14:55:58 GMT
  6. Organization: none
  7. Message-ID: <827765758snz@genesis.demon.co.uk>
  8. References: <4j2drs$q3r@dfw-ixnews3.ix.netcom.com> <3154F14C.35ED@ix.netcom.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <3154F14C.35ED@ix.netcom.com> bland@ix.netcom.com "Brian Land" writes:
  15.  
  16. >Andrew Heiz wrote:
  17. >> 
  18. >> Hi there,
  19. >> 
  20. >> Thanks for reading.
  21. >> 
  22. >> I have a simple question about using pointers to structures. I am
  23. >> imputing data into a structure using:
  24. >> 
  25. >>         gets(struct.element);
  26. >> 
  27. >> My question is in how to reference the structure element with a
  28. >> pointer. How do I do this?
  29.  
  30.    char *ptr = struct.element;    /* Substituting the real name for struct */
  31.  
  32. and then examine the first element of the array with, for example,
  33.  
  34.    ptr[0] or *ptr
  35.  
  36. >> 
  37. >
  38. >
  39. >How about....
  40. >
  41. >          gets( &(struct.element) );
  42.  
  43. No, a legal argument for gets() must be a pointer to the first element of
  44. an array of char. Therefore struct.element must be either an array of char
  45. or a pointer to char suitabbly set to point into another array. Either way
  46. you must write this as:
  47.  
  48.            gets(struct.element);
  49.  
  50. However using gets() in the first place strongly indicates Ansrew hasn't read
  51. the comp.lang.c FAQ.
  52.  
  53. -- 
  54. -----------------------------------------
  55. Lawrence Kirby | fred@genesis.demon.co.uk
  56. Wilts, England | 70734.126@compuserve.com
  57. -----------------------------------------
  58.